package com.qctpos.crm.openapi.controller;

import com.qctpos.crm.common.annotation.PassToken;
import com.qctpos.crm.common.annotation.ResponseResult;
import com.qctpos.crm.domain.dto.UserLoginDto;
import com.qctpos.crm.domain.dto.UserLoginResultDto;
import com.qctpos.crm.service.Demo1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@Controller
@Api(tags = "登录api")
public class LoginController {

    @Autowired
    private Demo1Service baseService;
    /**
     *
     * @return
     */
    @GetMapping(value ={"/","/swagger"})
    @ApiOperation(value = "swagger首页", notes = "swagger首页")
    public String Swagger(){

        //登录成功重定向到main.html;  重定向防止表单重复提交
        return "redirect:/swagger-ui/index.html";


    }

    @PassToken //不验证 token
    @PostMapping("/login")
    @ApiOperation(value = "登录", notes = "登录")
    @ResponseResult//自动封装成Result
    public UserLoginResultDto Login(@RequestBody UserLoginDto user) throws Exception {
        UserLoginResultDto userLoginResult = baseService.Login(user);
        return  userLoginResult;
    }

}
